package com.ajie.controller;


import com.ajie.entity.Comment;
import com.ajie.service.CommentService;
import com.ajie.utils.DateUtils;
import com.ajie.utils.QueryInfo;
import com.ajie.utils.Result;
import com.ajie.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "评论模块")
@RequestMapping("/comment")
@Slf4j
public class CommentControler {
    
    @Autowired
    private CommentService commentService;
    
    @ApiOperation(value = "发送评论")
    @PostMapping("/addComment")
    public Result addComment(@RequestBody Comment comment){
        log.info("该文件名是：CommentControler,该方法是：addComment");
        comment.setCommentUid(SecurityUtil.getUserId());
        comment.setTime(DateUtils.getDateTime());
        return commentService.addComment(comment);
    }
    
    @ApiOperation(value = "查看评论")
    @PostMapping("/findComment")
    public Result findComment( @RequestBody Comment comment){
        log.info("该文件名是：CommentControler,该方法是：findComment");
        return commentService.findComment(comment);
    }
    
    @ApiOperation(value = "删除评论")
    @DeleteMapping ("/delete/{id}")
    public Result deleteComment( @PathVariable("id") Long id){
        log.info("该文件名是：CommentControler,该方法是：deleteComment");
        return commentService.delete(id);
    }
    
    @ApiOperation(value = "查看评论")
    @PostMapping("/findAllComment")
    public Result findAllComment(@RequestBody QueryInfo queryInfo){
        log.info("该文件名是：CommentControler,该方法是：findComment");
        return commentService.findAllComment(queryInfo);
    }
    @ApiOperation(value = "修改评论状态")
    @PutMapping("/updateStatus/{id}")
    public Result updateStatus(@PathVariable("id") Long id){
        log.info("该文件名是：NewController,该方法是：update");
        return commentService.updateStatus(id);
    }

}
